<html>
<head>
    <meta charset="utf-8">
    <title>今日必推</title>
    <#assign base=request.contextPath  />
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${base}/backstage/layui/css/layui.css" media="all">
    <script src="${base}/sweep/js/mui.min.js"></script>
    <script src="${base}/backstage/layui/layui.js"></script>
    <script src="${base}/backstage/js/jquery-1.8.3.min.js"></script>
    <script src="${base}/backstage/js/feng.js"></script>
    <script>
        var base =  "${base}";
    </script>
    <script src="${base}/backstage/js/ipNameUrl.js"></script>
</head>
<body>

<table class="layui-hide" id="test1" lay-filter="test1"></table>
<script type="text/html" id="toolbarDemo1"></script>
<br>
<br>
<form class="layui-form " action="">
    <div class="layui-collapse">
<div class="layui-colla-item">
    <h2 class="layui-colla-title">今日必推</h2>
    <div class="layui-colla-content  layui-show">
        <table   class="layui-hide" id="test" lay-filter="test"></table>
    </div>
</div>
</div>
</form>



<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">设为今日必推</a>
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="del1">设为冰点秒杀</a>
</script>
<script type="text/html" id="toolbarDemo">
    <form class="layui-form " action="">
        <div class="layui-form-item">
            <label class="layui-form-label">用户</label>
            <div class="layui-input-block">
                <select name="client" lay-filter="account"  id="account" lay-search="">
                    <option value="">请选择用户</option>
                    <#list userInfo as userInfo>
                        <option value="${userInfo.id}">${userInfo.account}</option>
                    </#list>
                </select>
            </div>
        </div>

    </form>
</script>
</body>
<script>
    layui.use(['form', 'layer','table','element','laydate'], function() {
        var form = layui.form
            , layer = layui.layer;
        var table = layui.table;
        var laydate = layui.laydate;

        table.render({
            skin: 'line' //行边框风格
            , even: true //开启隔行背景
            , elem: '#test1'
            , url: '${base}/admin/good/selectMyPageQuality'
            , toolbar: '#toolbarDemo1'
            ,cols:[[
                {field:'id', title: '序号',templet:function(val){
                        return val.LAY_INDEX
                    },align:'center'},
                {field:'goodName', title: '商品名称', align:'center'},
                {field:'provisionalPrice', title: '暂定单价', align:'center'},
                {field:'profit', title: '商品盈利', align:'center'},
                {field:'goodPrice', title: '商品单价', align:'center'},
                {field:'commodityName', title: '商品分类', align:'center'},
                {field:'classificationName', title: '分类名称', align:'center'},
                {field:'type', title: '类型',templet:function(val){
                        if(val.type==undefined){
                            return "";
                        };
                        if(val.type==1){
                            return "<div style='background: #f0ad4e;color: #FFFFFF'>今日好货</div>";
                        };
                        if(val.type==2){
                            return "<div style='background: #1AB394;color: #FFFFFF'>冰点秒杀</div>";
                        }

                    },  align:'center'},
                {field:'createTime', title: '创建时间',templet:function(val){
                        if(val.createTime==undefined){
                            return "";
                        }
                        return changeDateFormat(val.createTime);
                    },  align:'center'}
                // {field: 'right', title: '操作', toolbar: '#barDemo', align: 'center'}
            ]]
            , id: 'testReload1'
            // , page: {
            //     layout: ['limit', 'count', 'prev', 'page', 'next', 'skip'] //自定义分页布局
            //     , theme: '#1AB394'
            //     , limit: 10
            // }
        });


        table.render({
            skin: 'line' //行边框风格
            , even: true //开启隔行背景
            , elem: '#test'
            , toolbar: '#toolbarDemo'
            , data: []
            , cols: [[
                {field: 'goodName', title: '商品名称'},
                {field: 'provisionalPrice', title: '暂定单价'},
                {field: 'profit', title: '商品盈利'},
                {field: 'goodPrice', title: '商品价格'},
                {field: 'commodityName', title: '商品分类'},
                {field: 'classificationName', title: '分类名称'},
                {field: 'createTime', templet:function(val){
                        if(val.createTime==undefined){
                            return "";
                        }
                        return changeDateFormat(val.createTime);
                    },title: '创建时间'},
                {field: '', title: '操作', toolbar: '#barDemo'},
            ]]
            ,page:false
            ,limits:[999999]
            ,limit:999999
            , id: 'testReload'

        });

        //今日必推
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                $.ajax({
                    type: "GET",
                    url: "${base}/admin/good/today_we_must_push",
                    data: {id: data.id},
                    success: function (data) {
                        if (data.code==200){
                            layer.msg(data.msg);
                            var table = layui.table;
                            //表刷新方法
                            table.reload('testReload1', {
                                url: '${base}/admin/good/selectMyPageQuality'
                                , where: {} //设定异步数据接口的额外参数
                            });
                        }else{
                            layer.msg(data.msg);
                        }
                    }
                });
            }
            if (obj.event === 'del1') {
                $.ajax({
                    type: "GET",
                    url: "${base}/admin/good/freezing_point_seckill",
                    data: {id: data.id},
                    success: function (data) {
                        if (data.code==200){
                            layer.msg(data.msg);
                            var table = layui.table;
                            //表刷新方法
                            table.reload('testReload1', {
                                url: '${base}/admin/good/selectMyPageQuality'
                                , where: {} //设定异步数据接口的额外参数
                            });
                        }else{
                            layer.msg(data.msg);
                        }
                    }
                });
            }
        });


        form.on('select(account)', function (data) {
            // 下拉框
            $.ajax({
                type: "GET",
                url: "${base}/admin/public/selectByUserId",
                data: {id: data.value},
                success: function (data) {
                    if (data.code==200){
                        var yuan = layui.table.cache.testReload;
                        if(yuan!=[]){
                            //重载表格  重载为空
                            var table = layui.table;
                            //表刷新方法
                            table.reload('testReload', {
                                data:[]
                                , where: {} //设定异步数据接口的额外参数
                            });
                        }
                        for (let i = 0; i < data.data.length; i++) {
                            var prod = data.data[i]
                            var prodJson = {
                                id:prod.id,//大类型
                                goodName:prod.goodName,//大类型
                                provisionalPrice:prod.provisionalPrice,//大类型名称
                                profit:prod.profit,//上工序 还本工序
                                goodPrice:prod.goodPrice, //小类型id
                                commodityName:prod.commodityName,//小类型名称
                                classificationName:prod.classificationName,//小类型名称
                                createTime:prod.createTime
                            }
                            layui.table.cache.testReload.push(prodJson);
                        }
                        table.reload('testReload', {
                            data: layui.table.cache.testReload
                        });
                    }

                }
            });
        });
    })



</script>
</html>


